﻿using System.Collections.Generic;

namespace FlickrSample.SL.Infrastructure.Flickr.Commands
{
    public class FlickrCommandBase : IFlickrCommand
    {
        string methodName;
        public FlickrCommandBase(string methodName)
        {
            this.methodName = methodName;
        }

        Dictionary<string, string> parameters = new Dictionary<string, string>();

        protected void AddParameter(string name, string value)
        {
            parameters.Add(name, value);
        }

        protected string ParameterValue(string key)
        {
            if (parameters.ContainsKey(key))
            {
                return parameters[key];
            }
            else
            {
                return null;
            }
            
        }

        #region IFlickrCommand Members

        public string MethodName
        {
            get 
            { 
                return methodName; 
            }
        }

        /// <summary>
        /// Some commands don't have a full command associated, like in FlickrPhotoInstanceCollection loading FlickrPhotoInstance
        /// They still need a way to be filed away on the file system though
        /// </summary>
        public IFlickrCommand SubCommand
        {
            get
            {
                FlickrCommandBase sub = new FlickrCommandBase(methodName + "_sub");
                foreach (string key in parameters.Keys)
                {
                    sub.AddParameter(key, parameters[key]);
                }
                return sub;
            }
        }

        public System.Collections.Generic.Dictionary<string, string> Parameters
        {
            get
            {
                return parameters;
            }
        }

        #endregion
    }
}
